﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterHome : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LiteralControl newln = new LiteralControl(Environment.NewLine);
        HtmlMeta language = new HtmlMeta();
        language.Name = "content-language";
        language.Content = Resources.Homepage.PageContent;

        Page.Header.Controls.AddAt(10, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(11, language);

        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");
        if (_strCXLive == "0")
        {
            if (Session[CE.Global.General.Guest] == null)
            {
                Response.Redirect("~/Default.aspx");
            }
            else if (Session[CE.Global.General.Guest].ToString() == "Provider")
            {
                if (Session[CE.Global.General.UserId] == null)
                {
                    Response.Redirect("~/provider/providersecurelogin.aspx");
                }
                else if (Session[CE.Global.General.UserTypeId] != null)
                {
                    if (Convert.ToInt32(Session[CE.Global.General.UserTypeId].ToString()) == Convert.ToInt32(CE.Global.CEUserType.Provider))
                    {
                        Response.Redirect("~/car-insurance/car-and-policy-details.aspx");
                    }
                    else
                    {
                        Response.Redirect("~/provider/providersecurelogin.aspx");
                    }
                }
                else
                {
                    Response.Redirect("~/provider/providersecurelogin.aspx");
                }
            }

        }
        else
        {
            //if (Session[CE.Global.General.Guest] == null)
            //{
            //    Response.Redirect("www.comparexpress.co.th");
            //}
        }


        if (Session[CE.Global.General.UserId] != null)
        {
            CE.Global.General.CreateUpdateUserLoginCached(Page);
            //imgLogin.ImageUrl = "/images/button/signout_lrg.gif";
            imgLogin.Visible = false;
            divUserName.Visible = true;
            string _userName = Session[CE.Global.General.UserName].ToString();
            if (_userName.Length > 20)
            {
                lblUserName.Text = _userName.Substring(0, 20) + "..";
            }
            else
            {
                lblUserName.Text = _userName;
            }
            hplLogin.ToolTip = _userName;
            hplLogin.Font.Underline = false;
        }

        if (Session[CE.Global.General.UserId] != null ||
            Session[CE.Global.General.CarId] != null)
        {
            Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "JS_AjaxSessionTimer", Resources.General.AJAXSessionTimerUrl);
            Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "JS_Net", "/includes/net.js");
        }
        if (!IsPostBack)
        {
            //Sakthi Added on 12 Jun 2014 - Start
            string _strCarRedirectURL = CE.Global.General.GetUrl("/car-insurance/car-details.aspx", Page);
            _strCarRedirectURL += "?type=hm";
            //Sakthi Added on 12 Jun 2014 - End

            //hplHome.NavigateUrl = CE.Global.General.GetUrl("/home.aspx", Page);
            //ImgWCbanner.ImageUrl = Resources.Football.ImgWCbanner;
            hplWCFball.NavigateUrl = CE.Global.General.GetUrl("/worldcup/football-contest.aspx", Page);
            //hplWCFballAd.NavigateUrl = CE.Global.General.GetUrl("/worldcup/football-contest.aspx", Page);
            //hplWCBanner.NavigateUrl = CE.Global.General.GetUrl("/worldcup/football-contest.aspx", Page);
            linkCarInsurance.NavigateUrl = _strCarRedirectURL;// CE.Global.General.GetUrl("/car-insurance/car-details.aspx", Page);
            hplSavingsPlan.NavigateUrl = CE.Global.General.GetUrl("/life/comingsoon.aspx", Page);
            hplClass.NavigateUrl = _strCarRedirectURL;// CE.Global.General.GetUrl("/car-insurance/car-details.aspx", Page);
            hplCTPL.NavigateUrl = CE.Global.General.GetUrl("/cmi/cmi-select.aspx", Page);

            hplFooterClass.NavigateUrl = _strCarRedirectURL;// CE.Global.General.GetUrl("/car-insurance/car-details.aspx", Page);
            hplFooterHome.NavigateUrl = CE.Global.General.GetUrl("/home.aspx", Page);
            hplAboutUs.NavigateUrl = CE.Global.General.GetUrl("/aboutus/", Page);
            hplFAQ.NavigateUrl = CE.Global.General.GetUrl("/faq/", Page);
            hplPrivacy.NavigateUrl = CE.Global.General.GetUrl("/privacy/", Page);
            hplTerms.NavigateUrl = CE.Global.General.GetUrl("/terms/", Page);
            hplSitemap.NavigateUrl = CE.Global.General.GetUrl("/sitemap/", Page);
            hplContactUs.NavigateUrl = CE.Global.General.GetUrl("/contactus/", Page);
            hplNews.NavigateUrl = CE.Global.General.GetUrl("/news/news.aspx", Page);
            hplMedia.NavigateUrl = CE.Global.General.GetUrl("/news/media.aspx", Page);

            hplChartis.HRef = CE.Global.General.GetUrl("/partners/chartis-insurance.aspx", Page);
            hplAZCP.HRef = CE.Global.General.GetUrl("/partners/azcp-insurance.aspx", Page);
            hplAXA.HRef = CE.Global.General.GetUrl("/partners/axa-insurance.aspx", Page);
            hplBKI.HRef = CE.Global.General.GetUrl("/partners/bki-insurance.aspx", Page);
            hplDhipaya.HRef = CE.Global.General.GetUrl("/partners/dhipaya-insurance.aspx", Page);
            hplKrungthai.HRef = CE.Global.General.GetUrl("/partners/krungthai-insurance.aspx", Page);
            hplKSK.HRef = CE.Global.General.GetUrl("/partners/ksk-insurance.aspx", Page);
            hplLMG.HRef = CE.Global.General.GetUrl("/partners/lmg-insurance.aspx", Page);
            hplMittare.HRef = CE.Global.General.GetUrl("/partners/mittare-insurance.aspx", Page);
            hplMSIG.HRef = CE.Global.General.GetUrl("/partners/msig-insurance.aspx", Page);
            hplMTI.HRef = CE.Global.General.GetUrl("/partners/muangthai-insurance.aspx", Page);
            //hplSCSMG.HRef = CE.Global.General.GetUrl("/partners/scsmg-insurance.aspx", Page);
            hplSMK.HRef = CE.Global.General.GetUrl("/partners/synmunkong-insurance.aspx", Page);
            hplThaivivat.HRef = CE.Global.General.GetUrl("/partners/thaivivat-insurance.aspx", Page);
            hplTMS.HRef = CE.Global.General.GetUrl("/partners/tokio-insurance.aspx", Page);
            hplViriyah.HRef = CE.Global.General.GetUrl("/partners/viriyah-insurance.aspx", Page);
            hplThaipaiboon.HRef = CE.Global.General.GetUrl("/partners/thaipaiboon-insurance.aspx", Page);
        }
    }
}
